package com.jasonzhou.onetomanycontrol.activity

import android.graphics.Color
import android.os.Bundle
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.viewbinding.ViewBinding
import com.jasonzhou.onetomanycontrol.adapter.CommonAdapter
import com.jasonzhou.onetomanycontrol.base.BaseActivity
import com.jasonzhou.onetomanycontrol.databinding.ActivityMainBinding
import com.jasonzhou.onetomanycontrol.databinding.ItemDeviceBinding

class MainActivity : BaseActivity<ActivityMainBinding>() {
    override fun getViewBinging() = ActivityMainBinding.inflate(layoutInflater)


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initView()
    }

    private fun initView() {
        binding.rv.apply {
            layoutManager = LinearLayoutManager(this@MainActivity)
            val deviceList = mutableListOf<String>().apply {
                add("123")
                add("456")
            }
            adapter = object : CommonAdapter<String, ViewBinding>(this@MainActivity, deviceList) {
                override fun getItemViewType(position: Int): Int {
                    return 0
                }

                override fun getViewBinding(parent: ViewGroup, viewType: Int): ViewBinding {
                    return ItemDeviceBinding.inflate(mInflater, parent, false)
                }

                override fun convert(v: ViewBinding, t: String, position: Int) {
                    when (v) {
                        is ItemDeviceBinding -> {
                            v.tvDeviceName.text = t
                            v.layout.setBackgroundColor(Color.RED)
                        }
                    }
                }

            }
        }
    }
}